package com.example.base.baseui;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;

import com.google.firebase.crashlytics.buildtools.reloc.com.google.common.eventbus.EventBus;
import com.google.firebase.crashlytics.buildtools.reloc.com.google.common.eventbus.Subscribe;

public abstract class BaseNormalFragment <VB extends ViewDataBinding> extends Fragment {
    protected VB mBinding;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBinding =  DataBindingUtil.inflate(inflater, getLayoutId(), container, false);
        try {
            EventBus.getDefault().register(this);
        }catch (Exception e){

        }
        mBinding.setLifecycleOwner(this);
        initData();
        return mBinding.getRoot();
    }

    protected abstract int getLayoutId();

    protected abstract void initData();

    @Subscribe(sticky = true,threadMode = ThreadMode.MAIN)
    public void onEventMainThread(String event){
        //你的逻辑
    }
    protected void showToast(String msg){
        Toast.makeText(getActivity(),msg, Toast.LENGTH_SHORT).show();
    }
    protected void showToast(@StringRes int msg){
        Toast.makeText(getActivity(),msg,Toast.LENGTH_SHORT).show();
    }
}
